#define DEBUG
#include <cstdio>

using namespace std;

const int maxn=200, maxm=600, maxu=100, inf=0x7ffffff;

class Graph {
public:
  static const int maxnode=maxn+4, maxside=maxm*maxu+4*maxn, ss=1, tt=2;
  int n, m=1, ind[maxnode+1], to[2*maxside+2], link[2*maxside+2], limit[2*maxside+2], val[2*maxside+2], cost=0, flow[maxnode+1];

  void init(int n) {
    this->n = n+2;
  }

  void addSide(int x, int y, int  l, int r, int v) {
    x+=2, y+=2;
    cost += l*v;
    flow[x]-=l, flow[y]+=l;
    m++;
    to[m] = y;
    val[m]=v;
    link[m] = ind[x];
    limit[m] = r-l;
    ind[x] = m;
    m++;
    to[m] = x;
    val[m] = 0;
    link[m]  = ind[y];
    limit[m] = 0;
    ind[y] = m;
    m++;
  }

  void build(int s, int t) {
    for (int i=3; i<=n; i++) {
      if (flow[i]>0) {
	addSide(i-2, tt-2, 0, flow[i], 0);
      } else if (flow[i]<0) {
	addSide(ss-2, i-2, 0, -flow[i], 0);
      }
    }
    s+=2, t+=2;
    addSide(t, s, 0, inf, 0);
  }

  int getAns() {
    static bool book[maxnode+1];
    static int que[maxnode+1], dis[maxnode+1];
    for (int i=1; i<=n; i++) {
      dis[i]=inf;
    }
    dis[ss]=0;
    que[1]=ss;
    book[ss]=true;
    for (int h=0, t=1; h!=t; ) {
      h = h%n+1;
      book[que[h]]=false;
      for (int i=ind[que[h]]; i; i=link[i]) {
	if (limit[i] && dis[to[i]]>dis[que[h]]+val[i]) {
	  dis[to[i]]=dis[que[h]]+val[i];
	  if (!book[to[i]]) {
	    t=t%n+1;
	    que[t]=to[i];
	    book[to[i]]=true;
	  }
	}
      }
    }
    return cost+dis[tt];
  }
};

int main() {
#ifdef DEBUG
  freopen("3302.in", "r", stdin);
  freopen("3302.out", "w", stdout);
#endif

  static Graph g;
  int n, m;
  scanf("%d %d", &n, &m);
  g.init(n+2);
  for (int i=1; i<=n; i++) {
    int left, in, out;
    scanf("%d %d %d", &left, &in, &out);
    g.addSide(1, i+2, 0, inf, in);
    g.addSide(i, 2, 0, inf, out);
    if (left>0) {
      g.addSide(1, i+2, left, left, 0);
    } else if (left<0) {
      g.addSide(i+2, 2, -left, -left, 0);
    }
  }
  for (int i=1; i<=m; i++) {
    int x, y, a, b, l, u;
    scanf("%d %d %d %d %d %d", &x, &y, &a, &b, &l, &u);
    for (int i=1; i<=l; i++) {
      g.addSide(x+2, y+2, 1, 1, (2*i-1)*a+b);
    }
    for (int i=l+1; i<=u; i++) {
      g.addSide(x+2, y+2, 0, 1, (2*i-1)*a+b);
    }
  }

  g.build(1, 2);
  printf("%d", g.getAns());

  fclose(stdin);
  fclose(stdout);
  return 0;
}
